package b.f.l;

import android.view.View;
import android.view.ViewTreeObserver;

public final class p implements ViewTreeObserver.OnPreDrawListener, View.OnAttachStateChangeListener {

    /* renamed from: b  reason: collision with root package name */
    private final View f1335b;

    /* renamed from: c  reason: collision with root package name */
    private ViewTreeObserver f1336c;

    /* renamed from: d  reason: collision with root package name */
    private final Runnable f1337d;

    private p(View view, Runnable runnable) {
        this.f1335b = view;
        this.f1336c = view.getViewTreeObserver();
        this.f1337d = runnable;
    }

    public static p a(View view, Runnable runnable) {
        if (view == null) {
            throw new NullPointerException("view == null");
        } else if (runnable != null) {
            p pVar = new p(view, runnable);
            view.getViewTreeObserver().addOnPreDrawListener(pVar);
            view.addOnAttachStateChangeListener(pVar);
            return pVar;
        } else {
            throw new NullPointerException("runnable == null");
        }
    }

    public void b() {
        (this.f1336c.isAlive() ? this.f1336c : this.f1335b.getViewTreeObserver()).removeOnPreDrawListener(this);
        this.f1335b.removeOnAttachStateChangeListener(this);
    }

    public boolean onPreDraw() {
        b();
        this.f1337d.run();
        return true;
    }

    public void onViewAttachedToWindow(View view) {
        this.f1336c = view.getViewTreeObserver();
    }

    public void onViewDetachedFromWindow(View view) {
        b();
    }
}
